define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wddj/vehicle/index' + location.search,
                    // add_url: 'wddj/vehicle/add',
                    // edit_url: 'wddj/vehicle/edit',
                    // del_url: 'wddj/vehicle/del',
                    // multi_url: 'wddj/vehicle/multi',
                    // import_url: 'wddj/vehicle/import',
                    table: 'vehicle',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'wechat_id', title: __('Wechat_id')},
                        // {field: 'driver_id', title: __('Driver_id')},
                        {field: 'wechat.nickname', title: __('Wechat.nickname'), operate: 'LIKE'},
                        {field: 'wechat.mobile', title: __('Wechat.mobile'), operate: 'LIKE'},
                        {field: 'wechat.avatar', title: __('Wechat.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'plate_number', title: __('Plate_number'), operate: 'LIKE'},
                        {field: 'license_front', title: __('License_front'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'license_back', title: __('License_back'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'plate_images', title: __('Plate_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'trailer.id', title: __('Trailer.id')},
                        // {field: 'trailer.wechat_id', title: __('Trailer.wechat_id')},
                        // {field: 'trailer.balance', title: __('Trailer.balance'), operate:'BETWEEN'},
                        // {field: 'trailer.createtime', title: __('Trailer.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'trailer.order_status', title: __('Trailer.order_status'), formatter: Table.api.formatter.status},
                        // {field: 'trailer.certified_id', title: __('Trailer.certified_id')},
                        // {field: 'trailer.status', title: __('Trailer.status'), formatter: Table.api.formatter.status},
                        // {field: 'trailer.driver_lng', title: __('Trailer.driver_lng'), operate: 'LIKE'},
                        // {field: 'trailer.driver_lat', title: __('Trailer.driver_lat'), operate: 'LIKE'},
                        // {field: 'trailer.channel', title: __('Trailer.channel')},
                        // {field: 'trailer.start_time', title: __('Trailer.start_time')},
                        // {field: 'trailer.end_time', title: __('Trailer.end_time')},
                        // {field: 'trailer.is_vehicle', title: __('Trailer.is_vehicle')},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
